package com.jinsi.controller;

import com.jinsi.pojo.Result;
import com.jinsi.pojo.Stu;
import com.jinsi.pojo.Tea;
import com.jinsi.utils.ExcelUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UploadFile {


    @ResponseBody
    @RequestMapping("/daoru")
    public Map<String,String> daoru(MultipartFile file){
        System.out.println(file);
        String originalFilename = file.getOriginalFilename();
        System.out.println(originalFilename);
        // 上传文件 目的
        // 1.上传文件转为list数据  2. 上传图片等存入服务器
        try {
            List<Tea> teas = ExcelUtils.importExcel(file, Tea.class);

            for (Tea tea:teas){
                System.out.println(tea);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        Map<String,String> map = new HashMap<>();

        // 批量插入

        map.put("state","200");
        map.put("msg","上传成功");


        return map;
    }
}
